<?php
//获取name
$adminAccount = $_POST['AdminAccount'] ?? '';

if (empty($adminAccount)){
    echo "参数错误";
    exit();
}
$adminPassword = $_POST['AdminPassword'];
//var_dump($_POST);

//连接数据库
$dsn = "sqlsrv:Server=localhost;Database=Task";
$db = new PDO($dsn, "sa", "123456");

// 判断任务是否存在
$selectSql = "select * from Admin where AdminAccount='{$adminAccount}'";
//var_dump($selectSql);
$statement = $db->query($selectSql);
//var_dump($statement);
$adminInfo = $statement->fetch(PDO::FETCH_ASSOC);
//echo "<pre>";
//var_dump($adminInfo);
//echo "</pre>";//不加$adminInfo &&就会导致账号对直接进
if ($adminInfo && $adminInfo['AdminPassword'] == $adminPassword){
    setcookie("AdminId", $adminInfo['AdminId']);//给退出登录用,还能用来显示当前用户
    setcookie("AdminAccount", $adminInfo['AdminAccount']);
    echo "登录成功<br />";
    echo "<a href='taskList.php'>返回任务列表页面</a>";
    exit();
}
echo "登录失败，账号或者密码错误。";